<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>跟随鼠标的天使</title>
    <style>
        img{
            position: absolute;
            top: 2px;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
   <img src="/5.jpg" alt="">
   <script>
       var pic = document.querySelector('img');
       document.addEventListener('mousemove',function(e) {
        //  mousemove 只要我们鼠标移动1px就会触发这个事件  
        //   
        var x = e.pageX;
        var y = e.pageY;
        // 3 千万不要忘记给left和top添加单位
        pic.style.left = x-100 + 'px';
        pic.style.top = y-100 + 'px';
       })
   </script>
</body>
</html>